﻿// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ExtendedReflection.Reasoning.InputGeneration;
using Microsoft.Pex.Engine.ComponentModel;
using Microsoft.ExtendedReflection.Reasoning.InputGeneration.SearchFrontiers;

namespace Microsoft.Pex.Fitness
{
    partial class PexSearchFrontierFittestFirstAttribute
    {
        class SearchFrontierFactory
            : ISearchFrontierFactory
        {
            private readonly StrategyKind strategy;
            private readonly IPexExplorationEngine host;
            public SearchFrontierFactory(
                IPexExplorationEngine host,
                StrategyKind strategy)
            {
                this.strategy = strategy;
                this.host = host;
            }

            ISearchFrontier<TNode> ISearchFrontierFactory.CreateFrontier<TNode>()
            {
                Random random = new Random(0);
                return
                    SearchFrontierFactory<TNode>.ShortCircuit(
                        SearchFrontierFactory<TNode>.CodeLocationPrioritized(
                            random,
                            null,
                            codeLocation => SearchFrontierFactory<TNode>.Shortest(int.MaxValue) // makes sure that all nodes with smallest depth are used
                        ),
                        new SearchFrontier<TNode>(this.host,
                            strategy,
                            random,
                            fitness => SearchFrontierFactory<TNode>.IterativeDeepening(random),
                            SearchFrontierFactory<TNode>.DefaultRoundRobin(random, null, null)));
            }
        }
    }
}
